# -*- coding: utf-8 -*-
import numbers
from typing import List


class Group:
    def __init__(self, group_name, company_name, staffs: List[str]):
        self.group_name = group_name
        self.company_name = company_name
        self.staffs = staffs

    def __reversed__(self):
        self.staffs.reverse()
        pass

    def __getitem__(self, item):
        """切片操作时运行该魔法函数"""
        # print(item)
        # return self.staffs[item]
        cls = type(self)
        if isinstance(item, slice):
            return cls(group_name=self.group_name, company_name=self.company_name, staffs=self.staffs[item])
        elif isinstance(item, numbers.Integral):
            return cls(group_name=self.group_name, company_name=self.company_name, staffs=[self.staffs[item]])

    def __len__(self):
        return len(self.staffs)

    def __iter__(self):
        return iter(self.staffs)

    def __contains__(self, item):
        return True if item in self.staffs else False


if __name__ == '__main__':
    _staffs = ['a','b','c','d']
    group = Group('group1', 'company1', staffs=_staffs)
    sub_group = group[:2]
    print(sub_group)
    g = group[3]
    print(g)
    print('a' in group)

    for _item in group:
        print(_item)

    res = reversed(group)
    print(group.staffs)

